package com.hamster.crm.web;


import com.hamster.crm.pojo.ProjectCategoryConfig;
import com.hamster.crm.pojo.ProjectParticipateConfig;
import com.hamster.crm.service.ProjectCategoryConfigService;
import com.hamster.crm.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author peichunting
 * @since 2019-12-19
 */
@RestController
@RequestMapping("/projectCategoryConfig")
public class ProjectCategoryConfigController {

    @Autowired
    private ProjectCategoryConfigService projectCategoryConfigService;

    @RequestMapping("/get")
    public ResponseEntity<ResponseResult> get(@RequestParam String id){
        ProjectCategoryConfig projectCategoryConfig = projectCategoryConfigService.get(id);
        return ResponseEntity.ok(ResponseResult.success(projectCategoryConfig));
    }

    @RequestMapping("/save")
    public ResponseEntity<ResponseResult> save(@RequestBody ProjectCategoryConfig projectCategoryConfig){

        if(projectCategoryConfigService.save(projectCategoryConfig)){
            return ResponseEntity.ok(ResponseResult.success(projectCategoryConfig));
        }else{
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
        }
    }

    @RequestMapping("/update")
    public ResponseEntity<ResponseResult> update(@RequestBody ProjectCategoryConfig projectCategoryConfig){

        if(projectCategoryConfigService.updateById(projectCategoryConfig)){
            return ResponseEntity.ok(ResponseResult.success(projectCategoryConfig));
        }else{
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
        }
    }

    @RequestMapping("/delete")
    public ResponseEntity<ResponseResult> delete(@RequestBody List<String> ids){
        if(projectCategoryConfigService.deletes(ids)){
            return ResponseEntity.ok(ResponseResult.success());
        }else{
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
        }

    }

    @RequestMapping("/list")
    public ResponseEntity<ResponseResult> list(){
        List<ProjectCategoryConfig> projectCategoryConfigs =  projectCategoryConfigService.listAll();
        return ResponseEntity.ok(ResponseResult.success(projectCategoryConfigs));
    }





}

